package com.xucia.auth.test;

import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.xucia.jsponic.data.Persistable;
import com.xucia.jsponic.datasource.DataSourceManager;
import com.xucia.jsponic.datasource.DataSourceObjectList;

public class FindUserEmailAddresses {
	
	public static void main(String[] args) {
		int i = 0;
		DataSourceObjectList websites = (DataSourceObjectList) DataSourceManager.getRootObject().get("websites");
		for (Object website : websites) {
			try {
				Persistable user = (Persistable) ((DataSourceObjectList) ((DataSourceObjectList) ((Persistable) website).get("groups")).get(3)).get(0);
				String emailAddress = (String) ((Persistable) user.get("userData")).get("email");
				if (i < 100) {
					System.err.println("address: " + emailAddress);
					sendEmail(emailAddress);
				}
				i++;
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
	private final static String HOST = "mail.kattare.com";
	private final static String USER_NAME = "kriszyp";
	private final static String PASSWORD= "23fropjik";
	private final static String PORT = "25";
	public static void sendEmail(String address) throws Exception{
        java.util.Properties props = new java.util.Properties(); 
        props.put("mail.smtp.host", HOST); 
        props.put("mail.smtp.auth", "true");
        props.put("mail.debug", true);        
        props.put("mail.smtp.user", USER_NAME);
        props.put("mail.smtp.password", PASSWORD);
        props.put("mail.smtp.port", PORT);

        Session s = Session.getInstance(props,null);
        s.setDebug(true);
        s.setDebugOut(System.err);
        InternetAddress from = new InternetAddress("Authenteo <info@authenteo.com>"); 
        InternetAddress to = new InternetAddress(address); 
        MimeMessage message = new MimeMessage(s); 
        message.setFrom(from); 
        message.addRecipient(Message.RecipientType.TO, to); 
        message.setSubject("Authenteo now available"); 
        message.setContent("<html>\n<body>\n<DIV style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><A name=OLE_LINK1><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\"><FONT color=#000000>Xucia is pleased to announce the release of the Authenteo web development system, the revolutionary new tool for building, managing, and maintaining next generation dynamic websites and rich Internet applications using a powerful </FONT></SPAN></A><st1:City><st1:place><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Ajax</SPAN></SPAN></st1:place></st1:City><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\"> framework with integrated layout and content control through our advanced browser-based WYSIWYG editor. <o:p></o:p></SPAN></SPAN></P>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\"><o:p>&nbsp;</o:p></SPAN></SPAN></P>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Authenteo has many powerful features that take web content management to the next level:<o:p></o:p></SPAN></SPAN></P>\n<UL type=disc>\n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">True WYSIWYG editing from your browser for both content and layout.&nbsp; Nothing could be simpler for content contributors and developers. This is the only WCM to allow you to actually manipulate the layout of a page from the browser editor, as well as the CSS and JavaScript for every component of your website.<o:p></o:p></SPAN></SPAN> \n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Powerful fine-grained security for defining different contributor roles and their permissions for team managed websites. <o:p></o:p></SPAN></SPAN>\n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"></SPAN><st1:City><st1:place><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Ajax</SPAN></SPAN></st1:place></st1:City><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\"> powered throughout.&nbsp;This is the definitive WCM for developing next generation Web 2.0 site and rich Internet applications. Powerful client side domain model access and continuation support provide the most intuitive and straightforward programming model for developing next generation web applications.<o:p></o:p></SPAN></SPAN> \n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Amazing extensibility.&nbsp;Website managers can dynamically modify every aspect of every component of a page from the unified page editing interface, including the JavaScript, </SPAN></SPAN><st1:stockticker><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">CSS</SPAN></SPAN></st1:stockticker><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">, and HTML. <o:p></o:p></SPAN></SPAN>\n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">And much more!&nbsp;See </SPAN></SPAN><A href=\"\"><U><FONT color=#800080><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">www.authenteo.com</SPAN></SPAN><SPAN style=\"mso-bookmark: OLE_LINK1\"></SPAN></FONT></U></A><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\"> for more.<o:p></o:p></SPAN></SPAN></LI></UL>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">For those who have previously signed up for a free trial Authenteo website, you may now sign for the full version of Authenteo for a special introductory price of $29 a month (regular price is $39 a month). The full version of Authenteo will allow you to have your own domain on the Authenteo system for commercial use as well as technical support. This is a remarkable deal for the most powerful RIA WCM on the market.<o:p></o:p></SPAN></SPAN></P>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\"><o:p>&nbsp;</o:p></SPAN></SPAN></P>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">You have received this email because you signed up for a free trial version of an Authenteo website. If you do not want to receive any more emails from us, please reply with <I style=\"mso-bidi-font-style: normal\">Remove </I>in the subject line.<SPAN style=\"mso-spacerun: yes\">&nbsp; </SPAN>However, we are excited about the numerous improvements to Authenteo over the last two months including:<o:p></o:p></SPAN></SPAN></P>\n<UL style=\"MARGIN-TOP: 0in\" type=disc>\n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">New components and page templates including: Reader's Comments, Products/Product Listings, and Email forms<o:p></o:p></SPAN></SPAN> \n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Persisted history of changes: <I style=\"mso-bidi-font-style: normal\">undo</I> and <I style=\"mso-bidi-font-style: normal\">redo</I> your changes, even across sessions<o:p></o:p></SPAN></SPAN> \n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Live auto merging of text changes.<SPAN style=\"mso-spacerun: yes\">&nbsp; </SPAN>Changes made to the live website are dynamically reflected in website versions.<SPAN style=\"mso-spacerun: yes\">&nbsp; </SPAN>You always know exactly what the published version will look like.<o:p></o:p></SPAN></SPAN> \n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Improved layout editing<o:p></o:p></SPAN></SPAN> \n<LI class=MsoNormal style=\"MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">Numerous performance improvement and bug fixes<o:p></o:p></SPAN></SPAN></LI></UL>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\"><o:p>&nbsp;</o:p></SPAN></SPAN></P>\n<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><SPAN style=\"mso-bookmark: OLE_LINK1\"><SPAN style=\"FONT-SIZE: 10pt; FONT-FAMILY: Tahoma\">We would love to hear your feedback on Authenteo. New features and improvements are being added constantly, and so we would love to hear what you would like to see improved or included in this product.<o:p></o:p></SPAN></SPAN></P></DIV>\n</body>\n</html>","text/html");
        URLName urlName = new URLName("smtp",HOST, -1, null,USER_NAME, PASSWORD);
        PasswordAuthentication auth = new PasswordAuthentication(USER_NAME,PASSWORD);
        s.setPasswordAuthentication(urlName,auth);
        Transport transport = s.getTransport(urlName);
        
    	//transport.connect("mail.kattare.com","kriszyp","23fropjik");
    	transport.send(message);
    	transport.close();
	}
}
